#coding=utf-8
import os
import shutil
import sys
import stat

def deleteSubFile(svnpath):
    names = os.listdir(svnpath)
    for name in names:
        
        fp = os.path.join( svnpath, name)
        if (os.path.isfile(fp)):
            os.chmod( fp, stat.S_IWRITE)
            os.remove(fp)
        else:
            deleteSubFile(fp)
            

def deleteSVN(parentPath = None, dir = None):
    if (dir != None and dir == '.svn'):
        deleteSubFile(os.path.join( parentPath, dir))
        shutil.rmtree(os.path.join( parentPath, dir), True, False)
        print 'deleted ', os.path.join( parentPath, dir)
    else:
        if (dir != None):
            filePath = os.path.join( parentPath, dir)
        else:
            filePath = parentPath
        names = os.listdir(filePath)
        for name in names:
            fp = os.path.join( filePath, name)
            if (os.path.isdir(fp)):
                deleteSVN(filePath, name)

if __name__ == '__main__':
    
    path = 'D:\\test'
    deleteSVN(path)
    